package com.ymatou.iapi.productcategory.testcase;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.ymatou.iapi.productcategory.parameter.BrandDto;
import com.ymatou.iapi.productcategory.parameter.GetTagInfoByCategoryIdBean;
import com.ymatou.iapi.productcategory.service.GetTagInfoByCategoryIdCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.database.annotation.SqlMapperFactory;
import com.ymttest.database.annotation.product.IntergratedProductMapper;
import com.ymttest.database.mongo.BuyerProductWapper;
import com.ymttest.utils.DiffUtil;
import com.ymttest.utils.EnvSetup;
/**
*FreeMaker Template自动生成代码
*/
import com.ymttest.utils.Logger2Debug;
import com.ymttest.utils.TestDataManager;

@TestSuite
public class Ts_GetTagInfoByCategoryId {
	private static GetTagInfoByCategoryIdCall GetTagInfoByCategoryIdCall;
	private static GetTagInfoByCategoryIdBean GetTagInfoByCategoryIdBean;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取所有的品牌信息");
	}

	@Before
	public void caseUp() {
		// 旧站点
//		GetTagInfoByCategoryIdCall = new GetTagInfoByCategoryIdCall(EnvSetup.getSystemUrl("productcategory_api"));
		//新站点
		GetTagInfoByCategoryIdCall = new GetTagInfoByCategoryIdCall();
		GetTagInfoByCategoryIdBean=new GetTagInfoByCategoryIdBean();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(GetTagInfoByCategoryIdCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GetTagInfoByCategoryId_001() {
		Logger.start(true, "获取品牌Tag信息");
		try {
			IntergratedProductMapper ipm = SqlMapperFactory
					.getIntergratedProductMapper();
			Map<String, Object> ainfo = ipm.selectAllTagInfo().get(0);
			Logger.debug(ainfo);
			GetTagInfoByCategoryIdBean.setCategoryId(ainfo.get("CategoryId").toString());
			GetTagInfoByCategoryIdCall.setData(GetTagInfoByCategoryIdBean);
			GetTagInfoByCategoryIdCall.callService();
			Logger.verifyEquals("200", GetTagInfoByCategoryIdCall.getString("Code"), "验证Code");
			Logger.debug(FormatUtil.beanToGSONString( GetTagInfoByCategoryIdCall.getTagInfoList()));
			List<Map<String, Object>> dblist = ipm.selectYMTCategoryTag(Integer.valueOf(GetTagInfoByCategoryIdBean.getCategoryId()));
			
			Logger.verifyEquals(dblist.size(), GetTagInfoByCategoryIdCall.getTagInfoList().size(), "验证数据");
			GetTagInfoByCategoryIdCall.getTagInfoList().forEach(x->{
				
				Map<String, Object> dbm = dblist.stream().filter(y->x.getTagId().equals(y.get("TagId"))).findFirst().get();
				Logger.verifyEquals(x.getName(),dbm.get("Name").toString(),"验证Name");
				Logger.verifyEquals(x.getTagValue(),dbm.get("TagValue").toString(),"验证TagValue");
				Logger.verifyEquals(x.getChooseType(),dbm.get("ChooseType"),"验证ChooseType");
			});
			
//			List<Map<String, Object>> list = ipm.selectTagConfig(GetTagInfoByCategoryIdBean.getCategoryId());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}